$('.datatable-basic').DataTable({
	 "ajax" : {
		"url" : contextpath + "withdrawBook/list",
		"data" : function(d) {
            var query = $("#query").serializeObject();
            query["size"] = d.length;
            query["page"] = (d.start/d.length);
			return query;
		},
		"dataFilter": function(data){
            var json = jQuery.parseJSON( data );
            json.recordsTotal = json.totalElements;
            json.recordsFiltered = json.totalElements;
            json.data = json.content;
 
            return JSON.stringify( json );
        }
	 },
	 "columns": [
         { "data": "name" },
         {
        	 render : function(data, type, row, meta) {
        		 if(row.type == '0'){
        			 return '渠道商';
        		 }else if(row.type == '1'){
        			 return '服务老师';
        		 }else {
        			 return '未知';
        		 }
             }
         },
         { "data": "withdrawRebate" },
         {
        	 render : function(data, type, row, meta) {
        		 if(row.status == '0'){
        			 return '已提现';
        		 }else if(row.status == '1'){
        			 return '待提现';
        		 }else {
        			 return '未知';
        		 }
             }
         },
         { "data": "customerName" },
         { "data": "bankName" },
         { "data": "bankCardNum" },
         { "data": "createTime" }
     ],
     "drawCallback": function( settings ) {
		 
		 $(".btn-withdraw").click(function(){
			var row = $('.datatable-basic').DataTable().row($(this).closest("tr")).data();
			swal({
				title : "提现",
				text : "确定用户为" + row.name + ",提现金额为" + row.withdrawRebate + "提现成功?",
				type : "warning",
				showCancelButton : true,
				confirmButtonColor : "#DD6B55",
				confirmButtonText : "确定",
				cancelButtonText: "取消",
				closeOnConfirm : false
			},function() {
				$.get(contextpath + "withdrawBook/withDraw/" + row.id, function(d){
					$('.datatable-basic').DataTable().draw();
					swal("提现成功","", "success");
				})
			});
			
		 });
      }
});

$(function(){
	
	$(".btn-add").click(function(){
		$("#edit").validate().resetForm();
	});
	 
	$("#submitEdit").click(function(){
		if($("#edit").valid()){
			$.post(contextpath + "withdrawBook/save", $("#edit").serialize(), function(){
				$('.close').click();
				swal("新增提现记录成功","", "success");
				$("#submit").click();
			})
		}
	});
	
    $("#submit").click(function(){
        $('.datatable-basic').DataTable().draw();
    });
        

	$('select').select2({
	    minimumResultsForSearch: Infinity
	});
})
